package com.hqbzl.c1;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class TestBigRoom {
    public static void main(String[] args) {
        final TestBigRoom room = new TestBigRoom();
        new Thread(() -> {
            room.sleep();
        }, "t1").start();
        new Thread(() -> {
            log.debug("study");
            room.study();
        }, "t2").start();

    }

    public void sleep() {
        synchronized (this) {
            log.debug("sleep()");
            try {
                TimeUnit.SECONDS.sleep(2);
                log.debug("sleeping");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void study() {
        synchronized (this) {
            log.debug("study()");
        }
    }
}
